package com.zhao.controller;

import com.zhao.dao.UniversityDao;
import com.zhao.pojo.University;
import com.zhao.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
public class RegisterController {

    @Autowired
    private RegisterService registerService;

    @Autowired
    private UniversityDao universityDao;

    @ResponseBody
    @RequestMapping("studentregister")
    public String studentRegister(String StudentID, String password, String username, String universityName, HttpSession session){

       try{
           University university = universityDao.findByName(universityName);
           if(university==null){
               System.out.println(university);
               System.out.println("学校名称错误");
               session.setAttribute("registMessage","学校名称错误");
               return "学校名称错误";
           }else {
               String result = registerService.studentRegister(StudentID,password,username,university.getUniversityID());
               System.out.println(result);
               return result;
           }

       }catch (Exception e){
           e.printStackTrace();
           return "系统出错";
       }

    }

}
